package com.cloudbroker.openapi.manage.controller;

import com.cloudbroker.bcs.common.entity.HSBCPSBackVO;
import com.cloudbroker.bcs.common.util.VOUtil;
import com.cloudbroker.bcs.common.util.ValueUtil;
import com.cloudbroker.bcs.common.util.VerifyCodeUtils;
import com.cloudbroker.bcs.platform.dav.bizapi.service.base.vo.HSBCPSVO;
import com.cloudbroker.bcs.platform.dav.bizapi.service.base.vo.PageVO;
import com.cloudbroker.bcs.platform.dav.bizapi.service.business.customer.back.*;
import com.cloudbroker.bcs.platform.dav.bizapi.service.business.customer.vo.*;
import com.cloudbroker.bcs.platform.dav.bizapi.service.common.sms.vo.SmsVerifyForm;
import com.cloudbroker.bcs.platform.dav.bizapi.service.viewpoint.vo.BrokerInfoForm;
import com.cloudbroker.bcs.platform.dav.bizapi.service.viewpoint.vo.NewsQueryForm;
import com.cloudbroker.bcs.platform.dav.bizapi.service.viewpoint.vo.NewsSaveForm;
import com.cloudbroker.bcs.platform.dav.bizapi.service.viewpoint.vo.NoticeInfoForm;
import com.cloudbroker.bcs.platform.dav.bizapi.t2service.business.UserManagerT2BizService;
import com.cloudbroker.bcs.platform.dav.bizapi.t2service.common.SmsT2BizService;
import com.cloudbroker.bcs.platform.dav.common.ext.annotation.SaveLog;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

import static com.cloudbroker.bcs.platform.dav.common.util.RequestUtil.getSingleParameterMapForBody;

@Controller
public class AccountController {
    
    @Resource
    private UserManagerT2BizService userManagerT2;
    
    @Resource
    private SmsT2BizService smsT2;
    
    /**
     * 发送验证短信
     */
    @ResponseBody
    @RequestMapping("/func_account_sendsms")
    @SaveLog(remark = "发送验证短信")
    public HSBCPSBackVO funcAccountSendSMS(HttpServletRequest request, String jsonpcallback) {
        SendSMSForm form = getSingleParameterMapForBody(request , SendSMSForm.class);
        return VOUtil.setJsonpResult(userManagerT2.funcAccountSendsms(form), jsonpcallback);
    }
    
    /**
     * 大V注册页面进入校验
     */
    @ResponseBody
    @RequestMapping("/func_broker_register_check")
    @SaveLog(remark = "大V注册页面进入校验")
    public BrokerRegFormBackForm funcBrokerRegisterCheck(HttpServletRequest request, String jsonpcallback) {
        BrokerRegCheckForm form = getSingleParameterMapForBody(request , BrokerRegCheckForm.class);
        return VOUtil.setJsonpResult(userManagerT2.funcBrokerRegisterCheck(form), jsonpcallback);
    }
    
    /**
     * 验证码效验
     */
    @ResponseBody
    @RequestMapping("/func_check_verify_code")
    @SaveLog(remark = "验证码效验")
    public HSBCPSBackVO funcCheckVerifyCode(HttpServletRequest request, String jsonpcallback) {
        SmsVerifyForm form = getSingleParameterMapForBody(request , SmsVerifyForm.class);
        return VOUtil.setJsonpResult(smsT2.funcCheckVerifyCode(form), jsonpcallback);
    }
    
    /**
     * 大V注册
     */
    @ResponseBody
    @RequestMapping("/func_broker_register")
    @SaveLog(remark = "大V注册")
    public LoginFormBackForm funcBrokerRegister(HttpServletRequest request, String jsonpcallback) {
        BrokerRegForm form = getSingleParameterMapForBody(request , BrokerRegForm.class);
        return VOUtil.setJsonpResult(userManagerT2.funcBrokerRegister(form), jsonpcallback);
    }
    
    /**
     * 官网注册
     * @param request
     * @param jsonpcallback
     * @return
     */
    @ResponseBody
    @RequestMapping("/func_website_register")
    @SaveLog(remark = "官网注册")
    public LoginFormBackForm funcWebsiteRegister(HttpServletRequest request, String jsonpcallback) {
        WebsiteRegForm form = getSingleParameterMapForBody(request , WebsiteRegForm.class);
        return VOUtil.setJsonpResult(userManagerT2.funcWebsiteRegister(form), jsonpcallback);
    }

    /**
     * 获取租户ID
     * @param request
     * @param jsonpcallback
     * @return
     */
    @ResponseBody
    @RequestMapping("/func_get_tenant")
    @SaveLog(remark = "获取租户ID")
    public TenantForm funcGetTenant(HttpServletRequest request, String jsonpcallback) {
        HSBCPSVO form = getSingleParameterMapForBody(request , HSBCPSVO.class);
        return VOUtil.setJsonpResult(userManagerT2.funcGetTenant(form), jsonpcallback);
    }
    
    /**
     * 投顾注册或登录
     * @param request
     * @param jsonpcallback
     * @return
     */
    @ResponseBody
    @RequestMapping("/func_register_or_login")
    @SaveLog(remark = "投顾注册或登录")
    public RegisterOrLoginBackForm funcRegisterOrLogin(HttpServletRequest request, String jsonpcallback) {
        RegisterOrLoginForm form = getSingleParameterMapForBody(request , RegisterOrLoginForm.class);
        return VOUtil.setJsonpResult(userManagerT2.funcRegisterOrLogin(form), jsonpcallback);
    }
    
    /**
     * 投顾完善信息
     * @param request
     * @param jsonpcallback
     * @return
     */
    @ResponseBody
    @RequestMapping("/func_broker_detail_update")
    @SaveLog(remark = "投顾完善信息")
    public HSBCPSBackVO funcBrokerDetailUpdate(HttpServletRequest request, String jsonpcallback) {
        BrokerDetailForm form = getSingleParameterMapForBody(request , BrokerDetailForm.class);
        return VOUtil.setJsonpResult(userManagerT2.funcBrokerDetailUpdate(form), jsonpcallback);
    }
    
    /**
     * 登陆
     */
    @ResponseBody
    @RequestMapping("/func_account_login")
    @SaveLog(remark = "登陆")
    public HSBCPSBackVO funcAccountLogin(HttpServletRequest request, String jsonpcallback) {
        LoginForm form = getSingleParameterMapForBody(request , LoginForm.class);
        return VOUtil.setJsonpResult(userManagerT2.funcAccountLogin(form), jsonpcallback);
    }
    
    /**
     * 登出
     */
    @ResponseBody
    @RequestMapping("/func_account_logout")
    @SaveLog(remark = "登出")
    public HSBCPSBackVO funcAccountLogout(HttpServletRequest request, String jsonpcallback) {
        HSBCPSVO form = getSingleParameterMapForBody(request , HSBCPSVO.class);
        return VOUtil.setJsonpResult(userManagerT2.funcAccountLogout(form), jsonpcallback);
    }
    
    /**
     * 注册用户总数
     */
    @ResponseBody
    @RequestMapping("/func_account_registernum")
    @SaveLog(remark = "注册用户总数")
    public HSBCPSBackVO funcAccountRegisternum(HttpServletRequest request, String jsonpcallback) {
        HSBCPSVO form = getSingleParameterMapForBody(request , HSBCPSVO.class);
        return VOUtil.setJsonpResult(userManagerT2.funcAccountRegisternum(form), jsonpcallback);
    }
    
    /**
     * 用户列表
     */
    @ResponseBody
    @RequestMapping("/func_account_list")
    @SaveLog(remark = "用户列表")
    public QueryAccountListFormBackForm funcAccountList(HttpServletRequest request, String jsonpcallback) {
        QueryAccountListForm form = getSingleParameterMapForBody(request , QueryAccountListForm.class);
        return VOUtil.setJsonpResult(userManagerT2.funcAccountList(form), jsonpcallback);
    }

    /**
     * 白名单列表
     */
    @ResponseBody
    @RequestMapping("/func_white_list")
    @SaveLog(remark = "白名单列表")
    public WhiteAccountListFormBackForm funcWhiteList(HttpServletRequest request, String jsonpcallback) {
        PageVO form = getSingleParameterMapForBody(request , PageVO.class);
        return VOUtil.setJsonpResult(userManagerT2.funcWhiteList(form), jsonpcallback);
    }
    
    /**
     * 加入/取消白名单
     */
    @ResponseBody
    @RequestMapping("/func_operator_white_list")
    @SaveLog(remark = "操作白名单列表")
    public HSBCPSBackVO funcOperatorWhiteList(HttpServletRequest request, String jsonpcallback) {
        OperatorWhiteListForm form = getSingleParameterMapForBody(request , OperatorWhiteListForm.class);
        return VOUtil.setJsonpResult(userManagerT2.funcOperatorWhiteList(form), jsonpcallback);
    }
    
    /**
     * 用户详细信息
     */
    @ResponseBody
    @RequestMapping("/func_account_detail")
    @SaveLog(remark = "用户详细信息")
    public CustomerIdFormBackForm funcAccountDetail(HttpServletRequest request, String jsonpcallback) {
        CustomerIdForm form = getSingleParameterMapForBody(request , CustomerIdForm.class);
        return VOUtil.setJsonpResult(userManagerT2.funcAccountDetail(form), jsonpcallback);
    }
    
    /**
     * 获取当前聊天室在线人数---大V端
     */
    @ResponseBody
    @RequestMapping("/func_chatroom_onlinenum_by_broker")
    @SaveLog(remark = "获取当前聊天室在线人数")
    public HSBCPSBackVO funcChatRoomOnlineNumByBroker(HttpServletRequest request, String jsonpcallback) {
        HSBCPSVO form = getSingleParameterMapForBody(request , HSBCPSVO.class);
        return VOUtil.setJsonpResult(userManagerT2.funcChatRoomOnlineNumByBroker(form), jsonpcallback);
    }
    
    /**
     * 修改密码
     */
    @ResponseBody
    @RequestMapping("/func_account_change_password")
    @SaveLog(remark = "修改密码")
    public HSBCPSBackVO funcAccountChangePassword(HttpServletRequest request, String jsonpcallback) {
        ChangePasswordForm form = getSingleParameterMapForBody(request , ChangePasswordForm.class);
        return VOUtil.setJsonpResult(userManagerT2.funcAccountChangePassword(form), jsonpcallback);
    }
    
    /**
     * 重置密码
     */
    @ResponseBody
    @RequestMapping("/func_account_reset_password")
    @SaveLog(remark = "重置密码")
    public HSBCPSBackVO funcAccountResetPassword(HttpServletRequest request, String jsonpcallback) {
        ResetPasswordForm form = getSingleParameterMapForBody(request , ResetPasswordForm.class);
        return VOUtil.setJsonpResult(userManagerT2.funcAccountResetPassword(form), jsonpcallback);
    }
    

    /**
     * 资讯信息保存
     * */
    @ResponseBody
    @RequestMapping("/func_news_save")
    @SaveLog(remark = "资讯信息保存")
    public HSBCPSBackVO funcNewsSave(HttpServletRequest request, String jsonpcallback) {
        NewsSaveForm form = getSingleParameterMapForBody(request, NewsSaveForm.class);
        return VOUtil.setJsonpResult(userManagerT2.funcNewsSave(form), jsonpcallback);
    }
    
    /**
     * 资讯信息查询
     * */
    @ResponseBody
    @RequestMapping("/func_news_qry")
    @SaveLog(remark = "资讯信息查询")
    public HSBCPSBackVO funcNewsQry(HttpServletRequest request, String jsonpcallback) {
        NewsQueryForm form = getSingleParameterMapForBody(request, NewsQueryForm.class);
        return VOUtil.setJsonpResult(userManagerT2.funcNewsQry(form), jsonpcallback);
    }
    

    @ResponseBody
    @RequestMapping("/func_broker_info_update")
    @SaveLog(remark = "大V个人信息修改")
    public HSBCPSBackVO funcBrokerInfoUpdate(HttpServletRequest request, String jsonpcallback) {
        BrokerInfoForm form = getSingleParameterMapForBody(request, BrokerInfoForm.class);
        return VOUtil.setJsonpResult(userManagerT2.funcBrokerInfoUpdate(form), jsonpcallback);
    }
    
    @ResponseBody
    @RequestMapping("/func_broker_notice_save")
    @SaveLog(remark = "消息保存")
    public HSBCPSBackVO funcBrokerNoticeSave(HttpServletRequest request, String jsonpcallback) {
        NoticeInfoForm form = getSingleParameterMapForBody(request, NoticeInfoForm.class);
        return VOUtil.setJsonpResult(userManagerT2.funcBrokerNoticeSave(form), jsonpcallback);
    }
    
    
    /**
     * 获取图片验证码
     */
    @ResponseBody
    @RequestMapping("/func_account_imgverify")
    @SaveLog(remark = "获取图片验证码")
    public HSBCPSBackVO funcAccountImgverify(HttpServletRequest request, HttpServletResponse response,
                                             String jsonpcallback) {
        ImgVerifyForm form = getSingleParameterMapForBody(request, ImgVerifyForm.class);
        ImgVerifyFormBackForm result = (ImgVerifyFormBackForm) userManagerT2.funcAccountImgverify(form);
        if (ValueUtil.getString(result.getError_no()).equals("0")) {
            String verifyCode = ValueUtil.getString(result.getVerify_code());
            int w = 107, h = 30;
            try {
                VerifyCodeUtils.outputImage(w, h, response.getOutputStream(), verifyCode);
            } catch (IOException e) {
                e.printStackTrace();
            }
            return VOUtil.setJsonpResult(result, jsonpcallback);
        }
        return VOUtil.setJsonpResult(result, jsonpcallback);
    }

    /**
     * 运营端大V列表
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping("/func_broker_account_list")
    @SaveLog(remark = "运营端大V列表")
    public BrokerAccountListBackForm funcBrokerAccountList(HttpServletRequest request , String jsonpcallback){
        QueryAccountListForm form = getSingleParameterMapForBody(request , QueryAccountListForm.class);
        return VOUtil.setJsonpResult(userManagerT2.funcBrokerAccountList(form), jsonpcallback);
    }

    /**
     * 运营端大V详细信息
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping("/func_broker_info")
    @SaveLog(remark = "运营端大V详细信息")
    public BrokerAccountInfoForm funcBrokerInfo(HttpServletRequest request , String jsonpcallback){
        FollowBrokerForm form = getSingleParameterMapForBody(request , FollowBrokerForm.class);
        return VOUtil.setJsonpResult(userManagerT2.funcBrokerInfo(form), jsonpcallback);
    }

    /**
     * 运营端大V更改状态
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping("/func_broker_change_status")
    @SaveLog(remark = "运营端大V更改状态")
    public HSBCPSBackVO funcBrokerChangeStatus(HttpServletRequest request , String jsonpcallback){
        BrokerStatusChangeForm form = getSingleParameterMapForBody(request , BrokerStatusChangeForm.class);
        return VOUtil.setJsonpResult(userManagerT2.funcBrokerChangeStatus(form), jsonpcallback);
    }
}
